/**
 * Company : Thai Informatic System Co., Ltd.
 * Created By : Dr.Tree
 * Created On : May 31, 2012  5:49:58 PM 
 * e-Mail : chatree@tis.co.th
 * Mobile Phone : (+66) 087-921-5115
 * Package Name : apps.business.process.construction.goods.returns
 * File Name : GoodsReturnProcessing.java
 * TODO
 */
package apps.business.process.construction.goods.returns;

import java.util.List;

import jpa.entitys.synchro.staging.MmReturndeliveryOutb;

import org.apache.log4j.Logger;

import promis.utility.CommonService;

import sap.business.mm.outbound.SyncReturndeliveryOutbService;

import apps.business.process.SyncProcessorCommons;
import apps.promis.out.construction.VwSyncGrtItemAction;

/**
 * @author chatree
 *
 */
public class GoodsReturnProcessing extends SyncProcessorCommons {
		
	private static final Logger log = Logger.getLogger(GoodsReturnProcessing.class);
	
	public GoodsReturnProcessing() {
		// TODO Auto-generated constructor stub
	}
	
	public void Processing(String company,String project,String documentNo,String status,String syncIsstaging) throws Exception {
		try{
			
			UPD_PROMISUseTime(true, false, null);
			List<MmReturndeliveryOutb> value_list = new VwSyncGrtItemAction().CreateToStaging(company, project, documentNo, status,syncIsstaging);
			UPD_PROMISUseTime(false, true, null);
			System.out.println("Create To Staging size=" + CommonService.getSize(value_list));
			
			if(CommonService.getSize(value_list) > 0){
				UPD_SENDUseTime(true, false, value_list.get(0).getInstanceNo());
				new SyncReturndeliveryOutbService().SendToSAP(value_list);
				UPD_SENDUseTime(false, true, value_list.get(0).getInstanceNo());
			}
			System.out.println("Sended to SAP size=" + CommonService.getSize(value_list));
			
		}catch(Exception e){
			e.printStackTrace();
			log.error(e.getMessage());
			System.err.println(e.getMessage());
			throw e;
		}
	}
	
	@Deprecated
	private void Start() throws Exception {
		try{
			VwSyncGrtItemAction oo = new VwSyncGrtItemAction();
			
			String company = "SP"; 
			String project = "SPLVILLE-PRAGSA"; 
			String documentNo = "79-1206-000001"; 
			String status = "A"; 
			String syncIsstaging = "N";
			List<MmReturndeliveryOutb> value_list = oo.CreateToStaging(company, project, documentNo, status,syncIsstaging);
			System.out.println("Create To Staging ---> " + CommonService.getSize(value_list));
			
			new SyncReturndeliveryOutbService().SendToSAP(value_list);
			System.out.println("Sended to SAP --->" + CommonService.getSize(value_list));
			
		}catch(Exception e){
			log.error(e.getMessage());
			System.err.println(e.getMessage());
			throw e;
		}
	}

//	/**
//	 * @param args
//	 */
//	public static void main(String[] args) {
//		// TODO Auto-generated method stub
//		
//		try{
//			new GoodsReturnProcessing().Start();
//		}catch(Exception e){
//			e.printStackTrace();
//		}
//
//	}

}
